package com.link2room.rodimus.service;

import com.link2room.common.dao.ICommonDao;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.exception.SysException;
import com.link2room.common.jpa.criteria.CriteriaUtil;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.rodimus.entity.CouponConsumeBaseEntity;
import com.link2room.rodimus.entity.Demo;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by sss on 2016/9/20.
 */
@Component("testService")
public class Test {
    @Resource
    private ICommonDao commonDao;


    public void m1(String rateId) throws Exception {
        Demo find = new Demo();
        find.setRateId(rateId);
        QueryResult<Demo> qres = commonDao.findAll(Demo.class, CriteriaUtil.getCriteriaAllEQ(find), null, null, null, null);
        for (int i = 0; i < qres.getResultlist().size(); i++){
            Demo e = qres.getResultlist().get(i);
            e.setNum(e.getNum()+1);
            commonDao.merge(e);
        }
    }


    @Transactional
    public void m2(String rateId) throws Exception {
        Demo find = new Demo();
        find.setRateId(rateId);
        Demo res = commonDao.findOne(Demo.class, CriteriaUtil.getCriteriaAllEQ(find));
        res.setNum(res.getNum() + 1);
        commonDao.merge(res);
    }
}
